package com.qf.electronic.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.electronic.common.R;
import com.qf.electronic.dto.LogDto;
import com.qf.electronic.pojo.Log;
import com.qf.electronic.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wu
 * @since 2023-05-04
 */
@RestController
@RequestMapping("/log")
public class LogController {


    @Autowired
    private ILogService logService;

    @GetMapping
    public R<Page<Log>> searchLogs(LogDto logDto){
        QueryWrapper<Log> wrapper = new QueryWrapper<>();
        String operationUser = logDto.getOperationUser();
        if(StringUtils.hasLength(operationUser))
            wrapper.like("operator_name", operationUser);
        String dateFrom = logDto.getDateFrom();
        if(StringUtils.hasLength(dateFrom))
            wrapper.ge("operation_time", dateFrom);
        String dateTo = logDto.getDateTo();
        if(StringUtils.hasLength(dateTo))
            wrapper.le("operation_time", dateTo);
        Page<Log> page = new Page<>(logDto.getCurrentPage(), logDto.getPageSize());
        return R.ok(logService.page(page, wrapper));
    }
}

